package com.mode;

import java.io.Serializable;
import java.sql.Date;
import java.util.ArrayList;
import java.util.Dictionary;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.List;

import android.R.bool;

public class SelectedProduct  implements Serializable {
	/**
	 * 
	 */
	private double sum=0;
	public boolean bState=false;
	public HashMap<String, List<SelectedMenuObj>> dicMenusHashtable=new HashMap<String, List<SelectedMenuObj>>();
	public String strdate;
	
	public SelectedProduct()
	{
		
	}
	public String getStrdate() {
		return strdate;
	}
	public void setStrdate(String strdate) {
		this.strdate = strdate;
	}
	public double getSum() {
		return sum;
	}

	public void setSum(double sum) {
		this.sum = sum;
	}
	
	public boolean isbState() {
		return bState;
	}

	public void setbState(boolean bState) {
		this.bState = bState;
	}
	
	public HashMap<String, List<SelectedMenuObj>> getDicMenusHashtable() {
		return dicMenusHashtable;
	}

	public void setDicMenusHashtable(
			HashMap<String, List<SelectedMenuObj>> dicMenusHashtable) {
		this.dicMenusHashtable = dicMenusHashtable;
	}
	@Override
	public String toString() {
		// TODO Auto-generated method stub
		return super.toString();
	}
	public void AddMenu(SelectedMenuObj menuinfo)
	{
		String cidString=menuinfo.getCid();
		if(!dicMenusHashtable.containsKey(cidString))
		{
			List<SelectedMenuObj> listmenu=new ArrayList<SelectedMenuObj>();
			dicMenusHashtable.put(cidString, listmenu);
		}
		List<SelectedMenuObj> list=dicMenusHashtable.get(cidString);
		boolean b=false;
		for (SelectedMenuObj selectedMenuObj : list) {
			if(selectedMenuObj.getId().equals(menuinfo.getId()))
			{
				selectedMenuObj.setCount(menuinfo.getCount());
				selectedMenuObj.setCommit(false);
				selectedMenuObj.totalPrice=selectedMenuObj.getCount()*selectedMenuObj.getPrice();
				b=true;
				break;
			}
		}
		if(!b)
		{
			list.add(menuinfo);
		}
		sum+=menuinfo.getPrice();
		bState=false;
	}
	public void RemoveMenu(SelectedMenuObj menuinfo)
	{
		String cidString=menuinfo.getCid();
		List<SelectedMenuObj> list=dicMenusHashtable.get(cidString);
		for (SelectedMenuObj selectedMenuObj : list) {
			if(selectedMenuObj.getId().equals(menuinfo.getId()))
			{
				selectedMenuObj=menuinfo;
				selectedMenuObj.totalPrice=selectedMenuObj.getCount()*selectedMenuObj.getPrice();
				break;
			}
		}
		sum-=menuinfo.getPrice();
		if(sum<=0)
		{
			sum=0;
		}
		bState=false;
	}
	public void DeleteMenu(SelectedMenuObj menuObj)
	{
		String cidString=menuObj.getCid();
		List<SelectedMenuObj> list=dicMenusHashtable.get(cidString);
		list.remove(menuObj);
		if(list.size()<=0)
		{
			dicMenusHashtable.remove(cidString);
		}
		sum-=menuObj.getTotalPrice();
		if(sum<=0)
		{
			sum=0;
		}
		bState=false;
	}
}
